﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class InputFieldControll : MonoBehaviour
{
    [SerializeField] GameObject Dog;
    [SerializeField] Rigidbody2D DogRig;
    [SerializeField] GameObject PickPos;
    [SerializeField] GameObject key;
    public bool ispicked = false;
    public InputField Instruction;
    public AudioSource DogBark;
    private void Start()
    {
        
    }
    public void ButtonDown()
    {
        if (Instruction.text == "go")
        {
            DogRig.velocity = new Vector2(4, 0);
        }
        if (Instruction.text == "stop")
        {
            DogRig.velocity = new Vector2(0, 0);
        }
        if (Instruction.text == "jump")
        {
            DogRig.velocity = new Vector2(0, 5);
        }
        if (Instruction.text == "back")
        {
            DogRig.velocity = new Vector2(-5,0);
        }
        if (Instruction.text == "bark")
        {
            DogBark.Play();
        }
        if (Instruction.text == "pick up")
        {
            if(Vector2.Distance(Dog.transform.position,key.transform.position)<=5)
            {
                key.transform.parent = PickPos.transform;
                key.transform.localPosition = new Vector3(0, 0, 0);
                ispicked = true;
            }
            
        }
        if (Instruction.text == "drop down")
        {
            if (ispicked==true)
            {
                key.transform.parent = null;
            }
        }
        if (Instruction.text == "bite")
        {
            
        }
        if (Instruction.text == "sit down")
        {
            
        }
    }

    /*private void OnCollisionStay2D(Collision2D collision)
    {
        if(collision.gameObject.tag=="object")
        {
            Debug.Log("1111");
            if (Instruction.text == "pick up")
            {
                collision.transform.parent = PickPos.transform;
                collision.transform.localPosition = new Vector3(0, 0, 0);
            }
        }
    }*/
}
